<?php

namespace app\cash\model;

use app\common\model\CommonModel;


class CashJointTableModel extends CommonModel{

    protected  $name = 'cash_joint_table';

    protected  $pk   = 'joint_table_id';
    /**
     * 模型写入前事件（钩子函数）
     */
    public static function onBeforeInsert($model)
    {
        $model->set("add_time", date('Y-m-d H:i:s'));
        $model->set("add_ip", request()->ip());
    }
    public static function info($where,$field='*'){
        $list = self::where($where)->field($field)->find();
        return $list;
    }
    public static function up($data,$where){
        $res=self::update($data,$where);
        return $res;
    }
    public static function list($where,$field){
        $list = self::alias('t')
            ->join('beautiful_table_number n','t.table_number_id=n.id')
            ->field($field)
            ->where(['t.is_delete'=>0,'n.is_delete'=>0])
            ->when(!empty($where['shop_id']),function ($query) use ($where){
                $query->where(['t.shop_id'=>$where['shop_id']]);
            })->when(!empty($where['master_table_number_id']),function ($query) use ($where){
                $query->where(['t.master_table_number_id'=>$where['master_table_number_id']]);
            })->when(!empty($where['status']),function ($query) use ($where){
                $query->where(['t.status'=>$where['status']]);
            })->when(!empty($where['type']),function ($query) use ($where){
                $query->where(['t.type'=>$where['type']]);
            })->select()->toArray();
        return $list;
    }
}

